home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / ca29_3.zip / BBSETUP.CMD < prev    next >
OS/2 REXX Batch file  |  1992-03-24  |  28KB  |  953 lines

  1.     SET TTHRU OFF        ; Must be 1st line to suppress typethrough
  2.     LEGEND "BBS Setup ver 1.0"
  3. ;****    TRACE ON        ; Debugging
  4. ;
  5. ; ----- COM-AND BBS setup script
  6. ;    Commenced: 11/90 R.McG
  7. ; -----------------------------------------------------------------------
  8. ;    Purpose:
  9. ;       This script, named BBSETUP.CMD, is executed to setup the BBS
  10. ;    script (version 1.1).  Setup 1) identifies the port and modem
  11. ;    control values, 2) identifies (and creates) the subdirs to be
  12. ;    used.  The script BBMAINT is used to update related files.
  13. ; -----------------------------------------------------------------------
  14. ;    NOTE: This script expects to find a file named BBSDAT on 1) the
  15. ;    current subdirectory, 2) The COM-AND= environment var specified
  16. ;    subdirectory, or 3) the subdirectory where THIS script resides.
  17. ;    If this file is found, it will be overwritten subsequently.  If
  18. ;    NOT found, BBSDAT will be created on the subdir where COM-AND=
  19. ;    points.  S29 is used to keep the file name (subroutine INIT).
  20. ; -----------------------------------------------------------------------
  21. ;
  22. ;    Establish a DWINDOW, and change the text display to window default.
  23. ;    .. Save the previous text display attribute, for restoration later.
  24. ;
  25.     DWIND 1,2 22,78     ; Establish scrolling region
  26.     N99 = "_TEXT"           ; Save original text attr
  27.     SET TEXT "_DEFA"        ; Set text attr
  28.     SET FLAG(9) OFF     ; Note if we did any saves
  29. ;
  30. ;    Perform tasks
  31. ;
  32.     GOSUB Init        ; Setup initial values
  33.     GOSUB Main        ; Paint main screen
  34. ;***    GOSUB ChkSave        ; Check if save needed
  35.     GOSUB ChkAll        ; Check if subd's exist
  36. ;
  37. ;    Exit the script
  38. ;
  39. Escape:
  40. Exit:
  41.     SET TEXT N99        ; Reset text attr finally
  42.     DWINDOW CLEAR        ; Clear any scrolling region
  43.     CLEAR            ; Clear entire text window
  44.     EXIT
  45. ; -----------------------------------------------------------------------
  46. ; ----- Subroutine: Init ->  Set initial values from BBSDAT
  47. ;    .. NOTE: S29 returns the file name to use for writes to BBSDAT
  48. ;
  49. Init:
  50.     S20 = "_PARM"(11:14)*","*"_PARM"(0:3) ; Port(4),speed(4)
  51.     S21 = "ATE0Q0V1X1S0=2 S7=30 S9=10^M"  ; Standard MINIT for BBS
  52.     S22 = "\BBS"            ; Set to our subdirectory
  53.     S23 = "\BBS\FILES"      ; Set subdir for files
  54.     S24 = "\BBS\MAIL"       ; Set subdir for mail
  55.     S25 = "\BBS\BULLETIN"   ; Set subdir for bulletins
  56. ;
  57. ;    Replace above values from BBSDAT, if that script exists
  58. ;
  59.     S29 = ""                ; Make value null
  60.     IF ISSC "BBSDAT"        ; If file exists on dft subdir or COM-AND=
  61.        FCALL "BBSDAT"       ; .. execute it
  62.     ELSE
  63.        S10 = "_SCRIPT"      ; Get current script fname
  64.        GOSUB Parse_Fname    ; Extract drive:Subdir from name
  65.        S10 = S10*"\BBSDAT"  ; Make new name
  66.        IF ISSC S10        ; Invoke it if its THERE
  67.           FCALL S10     ; Invoke it
  68.           S29 = S10     ; Save for later
  69.           ENDIF
  70.        ENDIF
  71.     RETURN            ; Done init
  72. ; -----------------------------------------------------------------------
  73. ;    Subroutine: Parse drive:subdirectory from file name
  74. ;
  75. ;    S10 passes fully name        S10 returns drive:subdirectory
  76. ;                    S11 returns file name
  77. ;    N10,N11 are scratch values
  78. ; -----------------------------------------------------------------------
  79. ;
  80. Parse_Fname:
  81.     LENGTH S10 N10            ; Find length of string
  82.     FOR N11 = (N10-1),0,-1        ; Scan backwards through string
  83.         IF STRCMP S10(N11:N11) ":" or STRCMP S10(N11:N11) "\" GOTO PAFN100
  84.         ENDFOR
  85.     S11 = S10            ; No drive or path
  86.     S10 = ""                        ; Return null drive:path spec
  87.     RETURN
  88. ;
  89. ;    Extract drive and path from name; N11 points to ":" or "\"
  90. ;
  91. PAFN100:
  92.     S11 = S10(N11+1:N10)        ; Extract name portion
  93.     IF STRCMP S10(N11:N11) "\" DEC N11
  94.     S10 = S10(0:N11)        ; Save ":", remove last "\"
  95.     RETURN
  96. ; -----------------------------------------------------------------------
  97. ; ----- Subroutine: Save -> Save values in BBSDAT
  98. ;    .. BBSDAT is placed in dft subdir; create file if need be
  99. ;
  100. Save:
  101.     IF NULL S29        ; If INIT did not set a name
  102.     ;
  103.     ; Construct a file name on the appropriate directory
  104.     ;
  105.        S1 = ""              ; Initialize file name string
  106.        IF NOT ISFIL "BBSDAT"; If not on current subdir
  107.           ENVIRON S1 "COM-AND="; Look for COM-AND= environment var
  108.           IF FOUND        ; If environment variable found
  109.          LENGTH S1 N0    ; Get its length
  110.          N0 = N0-1    ; Point to last char in string
  111.          IF not STRCMP S1(n0:n0) "\"
  112.             N0 = N0+1    ; Point after last char
  113.             CONCAT S1(n0) "\"
  114.             ENDIF
  115.          ENDIF
  116.           ENDIF
  117.        S1 = S1&"BBSDAT"     ; Add the necessary file name
  118.     ELSE S1 = S29        ; Else use name set by INIT
  119.     ;
  120.     ; Open the file, write the file, and close it
  121.     ;
  122.     FOPENO S1 TEXT        ; Open the file name so constructed
  123.     IF NOT SUCCESS
  124.        S0 = "Error opening BBSDAT file: "*S1
  125.        GOSUB Error        ; Report
  126.        RETURN        ; And we're done
  127.        ENDIF
  128.        S29 = "_OFILE"           ; Save file name we opened
  129.        ;
  130.        ; Write values we have as of now
  131.        ;
  132.     WRITE "; --- BBS initialization !" ; Write initial comments
  133.     WRITE ";     Updated "*"_DATE"*", at "*"_TIME"*"!"
  134.     WRITE ";!"                         ; Write initial comments
  135.  
  136.     WRITE "S20=`""*S20&"`"!"    ; Write port and speed
  137.     S0 = S21        ; Copy control string
  138.     PRESERVE S0        ; Make it printable
  139.     WRITE "S21=`""*S0&"`"!" ; Write modem control string
  140.     WRITE "S22=`""*S22&"`"!"; Write BBS subdir
  141.     WRITE "S23=`""*S23&"`"!"; Write BBS files subdir
  142.     WRITE "S24=`""*S24&"`"!"; Write BBS mail subdir
  143.     WRITE "S25=`""*S25&"`"!"; Write BBS bulletin subdir
  144.     WRITE "FRETURN!^Z "     ; Write end of file
  145.        ;
  146.        ; Close the file and we're done
  147.        ;
  148.     SET FLAG(9) ON        ; Note we did ONE save
  149.     FCLOSEO         ; Close the file
  150.     RETURN            ; And we're done
  151. ; -----------------------------------------------------------------------
  152. ; ----- Error:    Open a window, display a message, and wait for keypress
  153. ;    S0 passes the error message
  154. ;
  155. Error:
  156.     WOPEN 10,10,12,70 (cont) Err_Esc
  157.     ATSAY 10,12 (cont) " Error "
  158.     ATSAY 11,12 (cont) S0(0:55); Max msg width 55 chars
  159.     ATSAY 12,26 (cont) " Press any key to continue "
  160.     ;
  161.     ;    Wait a keypress
  162.     ;
  163.     KEYGET S0        ; Wait for any key
  164.     WCLOSE
  165. Err_Esc:
  166.     RETURN
  167. ; -----------------------------------------------------------------------
  168. ; ----- Subroutine: ChkSave ->    Save file?
  169. ;
  170. ChkSave:
  171.     IF FLAG(9) RETURN    ; At least one save was performed
  172.     WOPEN 0,0 23,79 (defa) Main_ESC
  173.     ATSAY 0,2 (defa)   " BBS Save "
  174.     ATSAY 23,25 (defa) " Press ESC to cancel BBSETUP "
  175. CHSA100:
  176.     CLEAR            ; Clear window
  177.     LOCATE 2,2
  178.     MESS " Do you wish to save the current values? (y/n) "
  179.     MESS "──────────────────────────────────── "
  180.     MESS "    Port and speed  is: "*S20
  181.     S0 = S21        ; Copy control string
  182.     PRESERVE S0        ; Make it printable
  183.     MESS "    Modem control   is: "*S0
  184.     MESS "    BBS main subdir is: "*S22
  185.     MESS "    Files subdir    is: "*S23
  186.     MESS "    Mail subdir     is: "*S24
  187.     MESS "    Bulletin subdir is: "*S25
  188.     MESS " "
  189.     MESS "──────────────────────────────────── "
  190.     MESS "Enter y or n (carriage return = n): "
  191. ;
  192. ;    Wait for a keypress
  193. ;
  194.     GET S0 1        ; Wait for it
  195.     IF NULL S0 GOTO CHSA200 ; If c/r, simply return
  196.     SWITCH S0        ; Act according to keyget
  197.       CASE "y"              ; Case insensitive
  198.            GOSUB Save
  199.            GOTO CHSA200
  200.            ENDCASE
  201.       CASE "n"              ; Case insensitive
  202.            GOTO CHSA200
  203.            ENDCASE
  204.       DEFAULT        ; None of the above
  205.            SOUND 100,100    ; Bronx cheer
  206.            ENDCASE
  207.       ENDSWITCH
  208.     GOTO CHSA100        ; Repaint screen and ask again
  209. ;
  210. ;    Exit, closing the window
  211. ;
  212. CHSA200:
  213.     WCLOSE
  214.     RETURN
  215. ; -----------------------------------------------------------------------
  216. ; ----- Subroutine: ChkAll ->  Check for subdir creation req'd
  217. ;
  218. ChkAll:
  219.     WOPEN 10,10 12,70 (cont)
  220.     ATSAY 10,12 (cont)   " BBS Subdirs "
  221.     ATSAY 11,12 (cont) " Checking existance of subdirs... "
  222.     PAUSE 1         ; Make it visible
  223. ;
  224. ;    Test for the existence of all subdirectories
  225. ;
  226.     SET FLAG(0) ON
  227.     FFIRST S22&"\*.*"       ; test for Main subd
  228.     IF SUCCESS SET FLAG(0) OFF
  229.  
  230.     SET FLAG(1) ON
  231.     FFIRST S23&"\*.*"       ; test for File subd
  232.     IF SUCCESS SET FLAG(1) OFF
  233.  
  234.     SET FLAG(2) ON
  235.     FFIRST S24&"\*.*"       ; test for Mail subd
  236.     IF SUCCESS SET FLAG(2) OFF
  237.  
  238.     SET FLAG(3) ON
  239.     FFIRST S25&"\*.*"       ; t